import { ClientMessage } from "@runtime/generate/message/ClientMessage";
import WebSocketComponent from "../WebSocket/WebSocketComponent";

/**
 * WebWindow组件
 */
export default class WebWindowComponent {
    private static instance: WebWindowComponent = new WebWindowComponent();
    /**
     * WebWindow组件
     */
    public static get Default(): WebWindowComponent {
        return this.instance;
    }

    constructor() {
        window.addEventListener('unload', this.Dispose.bind(this));
    }

    Dispose() {
        window.removeEventListener('unload', this.Dispose);
    }

    public SetBackground(red: number, green: number, blue: number, alpha: number): void {
        WebSocketComponent.Default.PostMessage(new ClientMessage.WebWindowSetBackgroundMessage(red, green, blue, alpha));
    }

    public SetTransparentBackground(): void {
        this.SetBackground(0, 0, 0, 0);
    }

    public SetBlackBackground(): void {
        this.SetBackground(0, 0, 0, 255);
    }

    public SetWhiteBackground(): void {
        this.SetBackground(255, 255, 255, 255);
    }
}